Optimisation système d'une boucle d'apprentissage Resnet-50.

Le but de ce notebook est d'optimiser un code d'apprentissage d'un modèle Resnet-50 sur Imagenet pour Jean Zay en implémentant :
Les cellules dans ce notebook ne sont pas prévues pour être modifiées, sauf rares exceptions indiquées dans les commentaires. Les TP se feront en modifiant le code dlojz.py.
Les directives de modification seront marquées par l'étiquette TODO :, dans le notebook suivant.
Les solutions sont présentes dans le répertoire solutions.
Notebook rédigé par l'équipe assistance IA de l'IDRIS, juin 2023
Un module PyTorch doit avoir été chargé pour le bon fonctionnement de ce Notebook. Nécessairement, le module pytorch-gpu/py3/1.11.0 :
!module list
Currently Loaded Modulefiles: 1) cuda/11.7.1 7) magma/2.7.0-cuda 2) nccl/2.12.12-1-cuda 8) sox/14.4.2 3) cudnn/8.5.0.96-11.7-cuda 9) sparsehash/2.0.3 4) gcc/8.5.0(8.3.1:8.4.1) 10) libjpeg-turbo/2.1.3 5) openmpi/4.1.1-cuda 11) pytorch-gpu/py3/2.0.0 6) intel-mkl/2020.4 >
Les fonctions python de gestion de queue SLURM dévelopées par l'IDRIS et les fonctions dédiées à la formation DLO-JZ sont à importer.
Le module d'environnement pour les jobs et la taille des images sont fixés pour ce notebook.
TODO : choisir un pseudonyme (maximum 5 caractères) pour vous différencier dans la queue SLURM et dans les outils collaboratifs pendant la formation et la compétition.
from idr_pytools import display_slurm_queue, gpu_jobs_submitter, search_log
from dlojz_tools import controle_technique, compare, GPU_underthehood, plot_accuracy, lrfind_plot, imagenet_starter
MODULE = 'pytorch-gpu/py3/1.11.0'
image_size = 176
account = 'for@v100'
name = 'pseudo' ## Pseudonyme à choisir
from idr_pytools import display_slurm_queue, gpu_jobs_submitter, search_log
from dlojz_tools import controle_technique, compare, GPU_underthehood, plot_accuracy, lrfind_plot, imagenet_starter
MODULE = 'pytorch-gpu/py3/1.11.0'
image_size = 176
account = 'sos@v100'
name = 'idris' ## Pseudonyme à choisir
Creation d'un repertoire checkpoints si cela n'a pas déjà été fait.
!mkdir checkpoints
Cette partie permet d'afficher et de gérer la queue SLURM.
Pour afficher toute la queue utilisateur :
display_slurm_queue(name)
Done!
Remarque: Cette fonction utilisée plusieurs fois dans ce notebook permet d'afficher la queue de manière dynamique, rafraichie toutes les 5 secondes. Cependant elle ne s'arrête que lorsque la queue est vide. Si vous désirez reprendre la main sur le notebook, il vous suffira d'arrêter manuellement la cellule avec le bouton stop. Cela a bien sûr aucun impact sur le scheduler SLURM. Les jobs ne seront pas arrêtés.
Si vous voulez arrêter des jobs dans la queue:
!scancel -u $USER#!scancel -u $USER
Cette partie debug permet d'afficher les fichiers de sortie et les fichiers d'erreur du job.
Il est nécessaire dans la cellule suivante (en décommentant) d'indiquer le jobid correspondant sous le format suivant.
*Remarque* : dans ce notebook, lorsque vous soumettrez un job, vous recevrez en retour le numéro du job dans le format suivant : jobid = ['123456']. La cellule ci-dessous peut ainsi être facilement actualisée."
jobid = ['1493206']
Fichier de sortie :
%cat {search_log(contains=jobid[0])[0]}
>>> Training on 1 nodes and 1 processes
model: Resnet-50
number of parameters: 25557032
global batch size: 128 - mini batch size: 128
Optimizer: SGD (
Parameter Group 0
dampening: 0
lr: 0.1
maximize: False
momentum: 0.9
nesterov: False
weight_decay: 0.0
)
DATALOADER 10 True True True 3 False
image batch shape : torch.Size([128, 3, 176, 176])
>>> Training complete in: 0:05:53.561484
>>> Training performance time: min 4.501930236816406 avg 4.766597509384155 seconds (+/- 0.14579007426206964)
>>> Loading performance time: min 0.00013065338134765625 avg 0.00015664100646972656 seconds (+/- 1.434471526857817e-05)
>>> Forward performance time: 1.8760071092722368 seconds (+/- 0.09052225345171229)
>>> Backward performance time: 2.901484557560512 seconds (+/- 0.08457200485922346)
>>> Peak Power during training: 62.22 W)
>>> Validation time estimation: 0:17:49.429900
>>> Sortie trace #####################################
>>>JSON {"GPU process - Forward/Backward": [6.2423787117004395, 5.0220746994018555, 4.957103490829468, 5.0125415325164795, 4.943894863128662, 4.966577529907227, 5.019651651382446, 4.99901819229126, 4.964149236679077, 4.885366678237915, 4.904692649841309, 4.781780242919922, 4.951511859893799, 4.84772253036499, 4.766597509384155, 4.684057712554932, 4.787169456481934, 4.795409679412842, 4.917107105255127, 4.681482791900635, 4.62136173248291, 4.676070213317871, 4.717148303985596, 4.702852964401245, 4.64032506942749, 4.7434868812561035, 4.692547082901001, 4.687806129455566, 4.651872873306274, 4.681207180023193, 4.635786294937134, 4.501930236816406, 4.82633376121521, 4.589520454406738, 4.554682970046997, 4.706907749176025, 4.620109558105469, 4.52482008934021, 4.774549961090088, 4.610376834869385, 4.6381542682647705, 4.710811138153076, 5.109354257583618, 4.724546909332275, 4.806366920471191, 4.937008380889893, 4.881795883178711, 4.729339838027954, 4.814107179641724, 4.803519010543823], "CPU process - Dataloader": [3.979201555252075, 0.0001895427703857422, 0.00014591217041015625, 0.00017380714416503906, 0.00013375282287597656, 0.00013637542724609375, 0.0001621246337890625, 0.0001347064971923828, 0.00015163421630859375, 0.00015854835510253906, 0.00017547607421875, 0.0001685619354248047, 0.00014591217041015625, 0.0001819133758544922, 0.00013637542724609375, 0.0001373291015625, 0.0001327991485595703, 0.00013065338134765625, 0.0001361370086669922, 0.00015592575073242188, 0.0001666545867919922, 0.0001628398895263672, 0.00017642974853515625, 0.00017499923706054688, 0.0001685619354248047, 0.00014543533325195312, 0.00013685226440429688, 0.00013947486877441406, 0.00013518333435058594, 0.00015878677368164062, 0.00015592575073242188, 0.0001609325408935547, 0.0001652240753173828, 0.0001544952392578125, 0.0001742839813232422, 0.00015854835510253906, 0.00015926361083984375, 0.00015854835510253906, 0.0001609325408935547, 0.00016069412231445312, 0.00016307830810546875, 0.00015592575073242188, 0.00015592575073242188, 0.00015783309936523438, 0.00017976760864257812, 0.00015854835510253906, 0.00015735626220703125, 0.00016188621520996094, 0.0001595020294189453, 0.000164031982421875]}
>>> Number of batch per epoch: 10010
Max Memory Allocated 0 Bytes
Tue Feb 21 21:41:18 CET 2023
Fichier d'erreur :
%cat {search_log(contains=jobid[0], with_err=True)['stderr'][0]}
Loading pytorch-gpu/py3/1.11.0
Loading requirement: cuda/11.2 nccl/2.9.6-1-cuda cudnn/8.1.1.33-cuda gcc/8.4.1
openmpi/4.1.1-cuda intel-mkl/2020.4 magma/2.5.4-cuda sox/14.4.2
sparsehash/2.0.3 libjpeg-turbo/2.1.3
+ srun python -u dlojz.py -b 128 --image-size 176 --test
/gpfslocalsup/pub/anaconda-py3/2021.05/envs/pytorch-gpu-1.11.0+py3.9.12/lib/python3.9/site-packages/apex/pyprof/__init__.py:5: FutureWarning: pyprof will be removed by the end of June, 2022
warnings.warn("pyprof will be removed by the end of June, 2022", FutureWarning)
real 6m27.615s
user 0m0.020s
sys 0m0.013s
+ date
Pour le debug ou pour comparer son code avec les solutions mises à disposition, la fonction suivante permet d'afficher une page html contenant un différentiel de fichiers texte.
s1 = "dlojz.py"
s2 = "./solutions/dlojz1_3.py"
compare(s1, s2)
Voir le résultat du différentiel de fichiers sur la page suivante (attention au spoil !) :
import os
import torchvision
import torchvision.transforms as transforms
import torch
import numpy as np
import matplotlib.pyplot as plt
transform = transforms.Compose([
transforms.RandomResizedCrop(176), # Random resize - Data Augmentation
transforms.RandomHorizontalFlip(), # Horizontal Flip - Data Augmentation
transforms.ToTensor(), # convert the PIL Image to a tensor
transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))
])
train_dataset = torchvision.datasets.ImageNet(root=os.environ['ALL_CCFRSCRATCH']+'/imagenet',
transform=transform)
train_dataset
Dataset ImageNet
Number of datapoints: 1281167
Root location: /gpfsscratch/idris/sos/commun/imagenet
Split: train
StandardTransform
Transform: Compose(
RandomResizedCrop(size=(176, 176), scale=(0.08, 1.0), ratio=(0.75, 1.3333), interpolation=bilinear, antialias=warn)
RandomHorizontalFlip(p=0.5)
ToTensor()
Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225))
)
train_loader = torch.utils.data.DataLoader(dataset=train_dataset,
batch_size=4,
shuffle=True)
batch = next(iter(train_loader))
print('X train batch, shape: {}, data type: {}, Memory usage: {} bytes'
.format(batch[0].shape, batch[0].dtype, batch[0].element_size()*batch[0].nelement()))
print('Y train batch, shape: {}, data type: {}, Memory usage: {} bytes'
.format(batch[1].shape, batch[1].dtype, batch[1].element_size()*batch[1].nelement()))
img = batch[0][0].numpy().transpose((1,2,0))
plt.imshow(img)
plt.axis('off')
labels_cls, labels_id = torch.load(os.environ['ALL_CCFRSCRATCH']+'/imagenet/meta.bin')
label = labels_cls[np.unique(labels_id)[batch[1][0].numpy()]]
_ = plt.title('label class: {}'.format(label[0]))
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
X train batch, shape: torch.Size([4, 3, 176, 176]), data type: torch.float32, Memory usage: 1486848 bytes Y train batch, shape: torch.Size([4]), data type: torch.int64, Memory usage: 32 bytes
val_transform = transforms.Compose([
transforms.Resize((256, 256)),
transforms.CenterCrop(224),
transforms.ToTensor(), # convert the PIL Image to a tensor
transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))])
val_dataset = torchvision.datasets.ImageNet(root=os.environ['ALL_CCFRSCRATCH']+'/imagenet', split='val',
transform=val_transform)
val_dataset
Dataset ImageNet
Number of datapoints: 50000
Root location: /gpfsscratch/idris/sos/commun/imagenet
Split: val
StandardTransform
Transform: Compose(
Resize(size=(256, 256), interpolation=bilinear, max_size=None, antialias=warn)
CenterCrop(size=(224, 224))
ToTensor()
Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225))
)
import torchvision.models as models
model = models.resnet50()
print('number of total parameters: {}'.format(sum([p.numel() for p in model.parameters()])))
print('number of trainable parameters: {}'.format(sum([p.numel() for p in model.parameters() if p.requires_grad])))
number of total parameters: 25557032 number of trainable parameters: 25557032
Ce TP consiste à appliquer le code baseline pour prendre en main les fonctionnalités de test et découvrir le code.
TODO :
dlojz.pyRemarque :
DON'T MODIFY dans le script ne doivent pas être modifiées.n_gpu = 1
batch_size = 128
command = f'dlojz.py -b {batch_size} --image-size {image_size} --test'
command
'dlojz.py -b 128 --image-size 176 --test'
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
jobid = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:20:00', constraint='v100-32g')
print(f'jobid = {jobid}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199600 jobid = ['199600']
Copier-coller la sortie jobid = ['xxxxx'] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobid = ['1493206']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199600 gpu_p13 idris ssos040 R 6:29 1 r6i3n2
Done!
controle_technique(jobid)
Train throughput: 26.94 images/second GPU throughput: 26.94 images/second epoch time: 47564.93 seconds training time estimation for 90 epochs (with validations): 1216.14 hours ----------- training step time average (fwd/bkwd on GPU): 4.751588 sec (38.7%/61.5%) +/- 0.114300 loading step time average (CPU to GPU): 0.000153 sec +/- 0.000015 ----------- ELIGIBLE to run 1 epochs
Le code baseline dlo-jz.py a été exécuté sur le CPU (contrairement à ce qui est indiqué par le contrôle technique) en mode test, soit sur 50 itérations.
Dans le prochain exercice nous verrons ensemble l'accélération sur 1 GPU.

TODO : dans le script dlojz.py :
gpu et envoyer le modèle dans la mémoire du GPU.# define model
gpu = torch.device("cuda")
model = models.resnet50()
model = model.to(gpu)
non_blocking=args.non_blocking sera utile plus tard lors de la définition d'un DataLoader distribué.# distribution of images and labels to all GPUs
images = images.to(gpu, non_blocking=args.non_blocking)
labels = labels.to(gpu, non_blocking=args.non_blocking)
et
# distribution of images and labels to all GPUs
val_images = val_images.to(gpu, non_blocking=args.non_blocking)
val_labels = val_labels.to(gpu, non_blocking=args.non_blocking)
## Initialisation
if idr_torch.rank == 0: accuracies = []
val_loss = torch.Tensor([0.]).to(gpu) # send to GPU
val_accuracy = torch.Tensor([0.]).to(gpu) # send to GPU
n_gpu = 1
batch_size = 128
command = f'dlojz.py -b {batch_size} --image-size {image_size} --test'
command
'dlojz.py -b 128 --image-size 176 --test'
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
jobid = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobid = {jobid}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199673 jobid = ['199673']
Copier-coller la sortie jobid = ['xxxxx'] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobid = ['1493317']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199673 gpu_p13 idris ssos040 R 0:57 1 r6i3n2
Done!
controle_technique(jobid)
Train throughput: 492.53 images/second GPU throughput: 493.14 images/second epoch time: 2601.41 seconds training time estimation for 90 epochs (with validations): 67.53 hours ----------- training step time average (fwd/bkwd on GPU): 0.259563 sec (32.8%/66.8%) +/- 0.001267 loading step time average (CPU to GPU): 0.000318 sec +/- 0.000022 ----------- ELIGIBLE to run 18 epochs
Afin de mesurer l'impact de la taille de batch sur l'occupation mémoire et sur le throughput, la cellule suivante permet de soumettre plusieurs jobs avec des tailles de batch croissantes. Dans les cas où la mémoire est saturée et dépasse la capacité du GPU, le système renverra une erreur CUDA Out of Memory.
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
n_gpu = 1
batch_size = [8, 16, 32, 64, 128, 256, 512, 1024]
command = [f'dlojz.py -b {b} --image-size {image_size} --test'
for b in batch_size]
jobids = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobids = {jobids}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199677 Submitted batch job 199678 Submitted batch job 199679 Submitted batch job 199680 Submitted batch job 199681 Submitted batch job 199682 Submitted batch job 199683 Submitted batch job 199684 jobids = ['199677', '199678', '199679', '199680', '199681', '199682', '199683', '199684']
Copier-coller la sortie jobids = ['xxxxx', ...] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobids = ['1493424', '1493432', '1493433', '1493434', '1493435', '1493436', '1493438', '1493440']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199683 gpu_p13 idris ssos040 R 1:53 1 r7i1n8
Done!
GPU_underthehood(jobids)
Batch size per GPU: 8 Max GPU Memory Allocated: 2.93 GB, Troughput: 238.643 images/second Batch size per GPU: 16 Max GPU Memory Allocated: 2.93 GB, Troughput: 355.177 images/second Batch size per GPU: 32 Max GPU Memory Allocated: 2.94 GB, Troughput: 396.966 images/second Batch size per GPU: 64 Max GPU Memory Allocated: 3.55 GB, Troughput: 438.130 images/second Batch size per GPU: 128 Max GPU Memory Allocated: 6.76 GB, Troughput: 491.544 images/second Batch size per GPU: 256 Max GPU Memory Allocated: 13.20 GB, Troughput: 491.079 images/second Batch size per GPU: 512 Max GPU Memory Allocated: 26.08 GB, Troughput: 482.917 images/second Batch size per GPU: 1024 CUDA out of memory Memory occupancy by Model part : 0.331 +/- 0.011 GB
Le dernier job a atteint le seuil CUDA Out Of Memory :
controle_technique([jobids[-1]])

TODO : dans le script dlojz.py :
from torch.cuda.amp import autocast, GradScaler
# Creates a GradScaler once at the beginning of training.
scaler = GradScaler()
with autocast(): dans la boucle de training et la boucle de validation....
# Runs the forward pass with autocasting.
with autocast():
outputs = model(images)
loss = criterion(outputs, labels)
...
loss.backward() et optimizer.step().# Scales loss. Calls backward() on scaled loss to create scaled gradients.
# Backward passes under autocast are not recommended.
# Backward ops run in the same dtype autocast chose for corresponding forward ops.
scaler.scale(loss).backward()
# scaler.step() first unscales the gradients of the optimizer's assigned params.
# If these gradients do not contain infs or NaNs, optimizer.step() is then called,
# otherwise, optimizer.step() is skipped.
scaler.step(optimizer)
# Updates the scale for next iteration.
scaler.update()
n_gpu = 1
batch_size = 128
command = f'dlojz.py -b {batch_size} --image-size {image_size} --test'
command
'dlojz.py -b 128 --image-size 176 --test'
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
jobid = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobid = {jobid}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199734 jobid = ['199734']
Copier-coller la sortie jobid = ['xxxxx'] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobid = ['1493501']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199734 gpu_p13 idris ssos040 R 0:33 1 r6i3n2
Done!
controle_technique(jobid)
Train throughput: 1017.32 images/second GPU throughput: 1019.63 images/second epoch time: 1259.46 seconds training time estimation for 90 epochs (with validations): 33.33 hours ----------- training step time average (fwd/bkwd on GPU): 0.125535 sec (37.5%/62.7%) +/- 0.002890 loading step time average (CPU to GPU): 0.000285 sec +/- 0.000032 ----------- ELIGIBLE to run 30 epochs
Afin de mesurer l'impact de la taille de batch sur l'occupation mémoire et sur le throughput, la cellule suivante permet de soumettre plusieurs jobs avec des tailles de batch croissantes. Dans les cas où la mémoire est saturée et dépasse la capacité du GPU, le système renverra une erreur CUDA Out of Memory.
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
n_gpu = 1
batch_size = [16, 32, 64, 128, 256, 512, 1024, 2048]
command = [f'dlojz.py -b {b} --image-size {image_size} --test'
for b in batch_size]
jobids = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobids = {jobids}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199740 Submitted batch job 199741 Submitted batch job 199742 Submitted batch job 199743 Submitted batch job 199744 Submitted batch job 199746 Submitted batch job 199747 Submitted batch job 199748 jobids = ['199740', '199741', '199742', '199743', '199744', '199746', '199747', '199748']
Copier-coller la sortie jobids = ['xxxxx', ...] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobids = ['1493508', '1493509', '1493511', '1493512', '1493513', '1493515', '1493516', '1493517']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199747 gpu_p13 idris ssos040 R 1:53 1 r7i1n8
Done!
GPU_underthehood(jobids)
Batch size per GPU: 16 Max GPU Memory Allocated: 1.78 GB, Troughput: 374.703 images/second Batch size per GPU: 32 Max GPU Memory Allocated: 1.79 GB, Troughput: 629.536 images/second Batch size per GPU: 64 Max GPU Memory Allocated: 2.01 GB, Troughput: 909.963 images/second Batch size per GPU: 128 Max GPU Memory Allocated: 3.68 GB, Troughput: 991.929 images/second Batch size per GPU: 256 Max GPU Memory Allocated: 7.00 GB, Troughput: 1048.639 images/second Batch size per GPU: 512 Max GPU Memory Allocated: 13.66 GB, Troughput: 1092.495 images/second Batch size per GPU: 1024 Max GPU Memory Allocated: 26.95 GB, Troughput: 1004.766 images/second Batch size per GPU: 2048 CUDA out of memory Memory occupancy by Model part : 0.353 +/- 0.014 GB
TODO : Choisir pour la suite du TP une taille de batch par GPU qui vous semble la plus pertinente selon le test précédent.
## Choisir un batch size optimal
bs_optim = 512
n_gpu = 1
command = f'dlojz.py -b {bs_optim} --image-size {image_size} --test'
command
'dlojz.py -b 512 --image-size 176 --test'
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
jobid = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobid = {jobid}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199760 jobid = ['199760']
Copier-coller la sortie jobids = ['xxxxx', ...] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobid = ['1493563']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199760 gpu_p13 idris ssos040 R 1:19 1 r6i3n2
Done!
controle_technique(jobid)
Train throughput: 1086.93 images/second GPU throughput: 1092.29 images/second epoch time: 1179.04 seconds training time estimation for 90 epochs (with validations): 31.61 hours ----------- training step time average (fwd/bkwd on GPU): 0.468741 sec (41.0%/68.5%) +/- 0.098402 loading step time average (CPU to GPU): 0.002309 sec +/- 0.013412 ----------- ELIGIBLE to run 32 epochs

TODO : dans le script dlojz.py :
memory_format avec torch.channels_last.# define model
gpu = torch.device("cuda")
model = models.resnet50()
model = model.to(gpu, memory_format=torch.channels_last)
memory_format avec torch.channels_last.# distribution of images and labels to all GPUs
images = images.to(gpu, non_blocking=args.non_blocking, memory_format=torch.channels_last)
labels = labels.to(gpu, non_blocking=args.non_blocking)
et
# distribution of images and labels to all GPUs
val_images = val_images.to(gpu, non_blocking=args.non_blocking, memory_format=torch.channels_last)
val_labels = val_labels.to(gpu, non_blocking=args.non_blocking)
n_gpu = 1
command = f'dlojz.py -b {bs_optim} --image-size {image_size} --test'
command
'dlojz.py -b 512 --image-size 176 --test'
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
jobid = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobid = {jobid}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199777 jobid = ['199777']
Copier-coller la sortie jobids = ['xxxxx', ...] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobid = ['1493619']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199777 gpu_p13 idris ssos040 R 1:16 1 r6i3n2
Done!
controle_technique(jobid)
Train throughput: 1711.24 images/second GPU throughput: 1725.34 images/second epoch time: 748.89 seconds training time estimation for 90 epochs (with validations): 21.50 hours ----------- training step time average (fwd/bkwd on GPU): 0.296753 sec (42.1%/65.6%) +/- 0.074354 loading step time average (CPU to GPU): 0.002446 sec +/- 0.014316 ----------- ELIGIBLE to run 41 epochs
Afin de mesurer l'impact de la taille de batch sur l'occupation mémoire et sur le throughput, la cellule suivante permet de soumettre plusieurs jobs avec des tailles de batch croissantes. Dans les cas où la mémoire est saturée et dépasse la capacité du GPU, le système renverra une erreur CUDA Out of Memory.
Soumission du job. Attention vous sollicitez les noeuds de calcul à ce moment-là.
Pour soumettre le job, veuillez basculer la cellule suivante du mode Raw NBConvert au mode Code.
n_gpu = 1
batch_size = [16, 32, 64, 128, 256, 512, 1024, 2048]
command = [f'dlojz.py -b {b} --image-size {image_size} --test'
for b in batch_size]
jobids = gpu_jobs_submitter(command, n_gpu, MODULE, name=name,
account=account, time_max='00:10:00', constraint='v100-32g')
print(f'jobids = {jobids}')
batch job 0: 1 GPUs distributed on 1 nodes with 1 tasks / 1 gpus per node and 10 cpus per task Submitted batch job 199779 Submitted batch job 199780 Submitted batch job 199781 Submitted batch job 199782 Submitted batch job 199783 Submitted batch job 199784 Submitted batch job 199785 Submitted batch job 199786 jobids = ['199779', '199780', '199781', '199782', '199783', '199784', '199785', '199786']
Copier-coller la sortie jobids = ['xxxxx', ...] dans la cellule suivante.
Puis, rebasculer la cellule précédente en mode Raw NBConvert, afin d'eviter de relancer un job par erreur.
#jobids = ['1493654', '1493656', '1493657', '1493658', '1493659', '1493660', '1493661', '1493662']
display_slurm_queue(name)
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
199786 gpu_p13 idris ssos040 R 2:16 1 r7i2n8
Done!
GPU_underthehood(jobids)
Batch size per GPU: 16 Max GPU Memory Allocated: 1.69 GB, Troughput: 377.253 images/second Batch size per GPU: 32 Max GPU Memory Allocated: 1.70 GB, Troughput: 698.160 images/second Batch size per GPU: 64 Max GPU Memory Allocated: 2.02 GB, Troughput: 1162.421 images/second Batch size per GPU: 128 Max GPU Memory Allocated: 3.69 GB, Troughput: 1445.677 images/second Batch size per GPU: 256 Max GPU Memory Allocated: 7.01 GB, Troughput: 1550.960 images/second Batch size per GPU: 512 Max GPU Memory Allocated: 13.67 GB, Troughput: 1687.810 images/second Batch size per GPU: 1024 Max GPU Memory Allocated: 26.96 GB, Troughput: 1593.292 images/second Batch size per GPU: 2048 CUDA out of memory Memory occupancy by Model part : 0.365 +/- 0.015 GB
